home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 …SCII & the Runetime Code / ADC Developer CD (1992-07) (''Butch ASCII And The Runtime Code'')_iso / Dev.CD 199207.iso / Development Platforms / Apple II / HyperCardIIGS / Sample.XCMDs / CBeep / CBeep.c next >
Encoding:
C/C++ Source or Header  |  1991-01-04  |  2.1 KB  |  99 lines  |  [TEXT/MPS ]

  1.  
  2. /*----------------------------------------------------------------------
  3.  
  4.   file CBeep.c
  5.  
  6.   This XCMD has the following syntax:
  7.  
  8.     CBeep        beep once
  9.     CBeep ##    beep n times
  10.     CBeep ?        display usage information
  11.     CBeep !        display version information
  12.  
  13.   Copyright Apple Computer, Inc.  1989-1991
  14.   All Rights Reserved.
  15.    
  16. ----------------------------------------------------------------------*/
  17.  
  18. #include <types.h>
  19. #include <MiscTool.h>
  20. #include <GSOS.h>
  21. #include <HyperXCMD.h>
  22.  
  23. /*
  24.     Globals
  25. */
  26.  
  27. int    _toolErr;
  28. XCMDPtr    gParamPtr;
  29.  
  30.  
  31. /*
  32.     Forwards
  33. */
  34. pascal void CBeep();
  35.  
  36.  
  37.  
  38. /*  We place the entry point function in its own segment, so the linker can
  39.     extract it and ensure that it's first in the load file.    */
  40.  
  41. segment "EntrySeg";
  42.  
  43. /*
  44.    This is the entry point to the program.  Make sure this procedure
  45.    comes first in the final OMF resource because this is where HyperTalk
  46.    will be jumping in.
  47.    
  48.    For a really simple XCMD you could just put the code all in here, but
  49.    for cleanliness' sake this example calls another routine from here.
  50.    
  51.   
  52. */
  53. pascal void EntryPoint(paramPtr)
  54. XCMDPtr paramPtr;
  55. {
  56.   CBeep(paramPtr);
  57. }
  58.  
  59.  
  60.  
  61. /*  All other code & data is placed in the "Main" segment    */
  62.  
  63. segment "Main";
  64.  
  65.  
  66.  
  67. /*  The actual CBeep function.  Interpret parameters and beep the speaker    */
  68.  
  69. pascal void CBeep(paramPtr)
  70. XCMDPtr paramPtr;
  71. {
  72.   short        beepCount;
  73.   short        counter;
  74.   Str255    str;
  75.   
  76.   char    *formStr    = "\pAnswer \"FORM: CBeep {count}\"";
  77.   char    *versionStr    = "\pAnswer \"CBeep XCMD v1.0\" & return & \"© 1991 Apple Computer, Inc.\"";
  78.   
  79.   gParamPtr = paramPtr;        /* put in a global for easy access in other funcs    */
  80.   
  81.   if (paramPtr->paramCount > 0)    {
  82.     ZeroToPas(*(paramPtr->params[0]), &str);
  83.     
  84.     beepCount = 0;
  85.     
  86.     if (str.text[0] == '?')            /* test for special characters    */
  87.       SendCardMessage(formStr);
  88.     else if (str.text[0] == '!')
  89.       SendCardMessage(versionStr);
  90.  
  91.     else beepCount = StrToNum(&str);        /* not a special - take as # of beeps */
  92.   }
  93.   else beepCount = 1;    /* no count, assume one */
  94.   
  95.   beepCount = (beepCount <= 15) ? beepCount : 15;    /* limit 15 beeps    */
  96.   
  97.   for (counter = 0; counter < beepCount; counter++) SysBeep();
  98. }
  99.